package com.itheima.day12;

import java.util.Random;
import java.util.Scanner;

public class Demo07 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要计算的图形:");
        System.out.println("0:正方形,1:长方形,2:园形");
        int i = sc.nextInt();
        switch (i) {
            case 0:
                squareOperation(sc);
                break;
            case 1:
                rectangleOperation(sc);
                break;
            case 2:
                roundOperation();
                break;
            default:
                System.out.println("输入错误");
                break;
        }
    }

    private static void roundOperation() {
        System.out.println("请输入圆的半径:");
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        Round round = new Round(r);
        System.out.println("圆的周长是:" + round.getPerimeter());
        System.out.println("圆的面积是:" + round.getArea());
    }

    private static void squareOperation(Scanner sc) {
        System.out.println("请输入正方形的边长:");
        double side = sc.nextDouble();
        Square s = new Square(side);
        System.out.println("正方形的周长是:" + s.getPerimeter());
        System.out.println("正方形的面积是:" + s.getArea());
    }

    private static void rectangleOperation(Scanner sc) {
        System.out.println("请输入长方形的宽:");
        double width = sc.nextDouble();
        System.out.println("请输入长方形的高:");
        double height = sc.nextDouble();
        Rectangle rectangle = new Rectangle(width, height);
        System.out.println("长方形的周长是:" + rectangle.getPerimeter());
        System.out.println("长方形的面积是:" + rectangle.getArea());
    }
}

class Square {
    private double side;

    public Square() {
    }

    public Square(double side) {
        this.side = side;
    }

    public double getSide() {
        return side;
    }

    public void setSide(double side) {
        this.side = side;
    }

    public double getPerimeter() {
        return side * 4;
    }

    public double getArea() {
        return side * side;
    }
}

class Rectangle {
    private double width;
    private double height;

    public Rectangle() {
    }

    public Rectangle(double width, double height) {
        this.width = width;
        this.height = height;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public double getPerimeter() {
        return (width + height) * 2;
    }

    public double getArea() {
        return width * height;
    }
}

class Round {
    private double r;

    public Round() {
    }

    public Round(double r) {
        this.r = r;
    }

    public double getR() {
        return r;
    }

    public void setR(double r) {
        this.r = r;
    }

    public double getPerimeter() {
        return 2 * 3.14 * r;
    }

    public double getArea() {
        return 3.14 * r * r;
    }
}

